package com.itedge.solutionmanager.service.task.impl.customer;

import org.activiti.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itedge.solutionmanager.domain.impl.Customer;
import com.itedge.solutionmanager.enumeration.CustomerStatus;
import com.itedge.infrastructure.service.domain.IProcessEntityService;
import com.itedge.infrastructure.service.process.IProcessService;
import com.itedge.infrastructure.service.task.ITaskService;
import com.itedge.infrastructure.service.taskdata.ITaskDataEntityService;
import com.itedge.solutionmanager.taskdata.impl.customer.FreezeCustomerTaskData;

@Service
public class FreezeCustomerTaskService implements ITaskService<FreezeCustomerTaskData, Customer> {

    @Autowired
    protected TaskService taskService;
    @Autowired
    private IProcessEntityService<Customer> customerService;
    @Autowired
    private IProcessService<Customer> customerProcessService;
    @Autowired
    private ITaskDataEntityService<FreezeCustomerTaskData> freezeCustomerTaskDataService;
	
	@Override
	@Transactional
	public void completeTask(String taskId, Customer linkedObject,
			FreezeCustomerTaskData taskData, String user) {
    	freezeCustomerTaskDataService.merge(taskData);
    	linkedObject.setStatus(CustomerStatus.DEACTIVATED);
        customerService.merge(linkedObject);
        customerProcessService.cancelAllPendingTasksByTaskTrigger(linkedObject.getProcessInstanceId(), taskId);
    	taskService.setAssignee(taskId, user);
    	taskService.complete(taskId);	
	}

}
